home *** CD-ROM | disk | FTP | other *** search
/ NBC Slam Jams! / NBC Slam Jams!.iso / xtras / media_la / effector.cst / 00046_Script_slider < prev    next >
Text File  |  1997-09-30  |  5KB  |  157 lines

  1. -- Slider
  2.  
  3.  
  4.  
  5.  
  6.  
  7. property button, bar, direction, min, max, percentage, range, offset, Location,Name,downMem
  8. property msgMovie,msgSprite,msgSpriteNum,sliderMsg,defaultVal
  9. -- a simple horizontal or vertical slider.
  10. -- properties:
  11. --    button; the sprite number of the slider 'button' (the thing that slides)
  12. --    bar; the sprite number of the slider bar itself.
  13. --    direction; #Horizaontal or #Vertical
  14. --    min; the pixel value of the left (or bottom) end of the slider
  15. --    max; the pixel value of the right (or top) end of the slider
  16. --    percentage; the current percentage value represented by the slider
  17. --    range; the number of pixels between 'min' and 'max'
  18. --    offset; the actual pixel location along the slider
  19. --    location; the fixed location of the slider.  This does not change, unless the actual
  20. --    location of the slider changes.
  21. --    the developer needs to provide a handler called "sliderIsMoving" which is called whenever the slider's value is changed.
  22.  
  23. on getPropertyDescriptionList
  24.   
  25.   set s=the currentSpriteNum
  26.   if s>0 then
  27.     set nameDef=(the name of member (the member of sprite s))
  28.     set memDef= nameDef & "*"
  29.     set barDef=s-1
  30.   end if
  31.   set pList=[:]
  32.   addProp pList, #Name,[#comment:   "Slider Name:", ¼
  33.                             #format:   #string, ¼
  34.                            #default:    nameDef ]
  35.   
  36.   addProp pList, #DownMem,[#comment:   "Hilite Image:", ¼
  37.                             #format:   #graphic, ¼
  38.                            #default:    memDef ]
  39.   
  40.   addProp pList,#bar,[#comment:  "Range channel:",¼
  41.                              #format: #integer,¼
  42.                             #default: barDef]
  43.   
  44.   addProp pList,#direction,[#comment:"Direction:",¼
  45.                             #format: #symbol,¼
  46.                              #default:#Horizontal,¼
  47.                             #range:[#Horizontal,#Vertical]]
  48.   
  49.   addProp pList,#defaultVal,[#comment:"Default Value (%):",¼
  50.                             #format: #integer,¼
  51.                              #default:1]
  52.   
  53.   addProp pList,#msgMovie,[#comment:"Message Movie:",¼
  54.                             #format: #boolean,¼
  55.                              #default:1]
  56.   
  57.   addProp pList,#msgSprite,[#comment:"Message Sprite:",¼
  58.                             #format: #boolean,¼
  59.                              #default:0]
  60.   
  61.   addProp pList,#msgSpriteNum,[#comment:"Sprite Number:",¼
  62.                             #format: #integer,#default:1]
  63.   
  64.   addProp pList,#sliderMsg,[#comment:"Send this message:",¼
  65.                             #format: #string,¼
  66.                              #default:"sliderIsMoving"]
  67.   
  68.   return pList
  69. end
  70.  
  71. on getBehaviorDescription
  72.   return "Creates a slider"
  73. end
  74.  
  75. on beginSprite me
  76.   set sliderMsg=value("#" & sliderMsg)
  77.   set button=the spriteNum of me
  78.   setDirection(me)
  79.   set offset = 0
  80.   if defaultVal<1 then set defaultVal=1
  81.   if defaultVal>100 then set defaultVal=100
  82.   setSlider me, defaultVal
  83.   return me
  84. end
  85.  
  86. on setBar me, b
  87.   set bar = b
  88.   setDirection(me)
  89. end
  90.  
  91. on setLocation me,l
  92.   case direction of
  93.     #Horizontal: set the locV of sprite button = l
  94.     #Vertical: set the locH of sprite button = l
  95.   end case
  96.   setSlider me,percentage
  97. end
  98.  
  99. on mouseDown me
  100.   operate(me)
  101. end
  102.  
  103. on operate me  
  104.   set the member of sprite button = member downMem
  105.   repeat while the mouseDown
  106.     if direction=#horizontal then
  107.       set mh = the mouseH
  108.       if mh < min then set mh=min
  109.       if mh > max then set mh=max
  110.       set the locH of sprite button = mh
  111.       set offset = mh - min
  112.     else -- vertical
  113.       set mv= the mouseV
  114.       if mv > min then set mv=min
  115.       if mv<max then set mv=max
  116.       set the locV of sprite button = mv
  117.       set offset = min-mv
  118.     end if
  119.     set percentage = (offset*100) / range
  120.     if msgMovie then sliderIsMoving(me)
  121.     if msgSprite then sendSprite(msgSpriteNum,sliderMsg,Name,percentage)
  122.     sendSprite(button,#step)
  123.     updateStage
  124.   end repeat
  125. end
  126.  
  127. on setSlider me,p,flag
  128.   set percentage = p
  129.   set offset = (range*percentage) / 100
  130.   case direction of
  131.     #Horizontal: set the locH of sprite button = offset+min
  132.     #Vertical: set the locV of sprite button = min-offset
  133.   end case
  134.   if voidP(flag) then
  135.     if msgMovie then sliderIsMoving(me)
  136.     if msgSprite then sendSprite(msgSpriteNum,sliderMsg,Name,percentage)
  137.   end if
  138.   updateStage
  139. end
  140.  
  141. on setDirection me,d
  142.   if not voidP(d) then set direction=d
  143.   case direction of
  144.     #horizontal:
  145.       set min = the left of sprite bar
  146.       set max = the right of sprite bar
  147.       set range = max - min
  148.       --set location = the locV of sprite button
  149.     #vertical:
  150.       set min = the bottom of sprite bar
  151.       set max = the top of sprite bar
  152.       set range = min - max -- it's backwards because of the screen coordinates
  153.       --set location = the locH of sprite button
  154.   end case
  155. end
  156.  
  157.